001 /**
002 * Created by IntelliJ IDEA.
003 * User: Wei Wang
004 * Date: Nov 28, 2002
005 * Time: 12:45:22 AM
006 */
007
008 package EVolve.visualization.XYViz.RefRefViz;
009
010 import EVolve.visualization.XYViz.XYVisualization;
011 import EVolve.visualization.*;
012 import EVolve.visualization.Dimension;
013 import EVolve.Scene;
014 import EVolve.exceptions.NoDataPlotException;
015
016 import java.util.ArrayList;
017 import java.util.HashMap;
018
019 public abstract class ReferenceReferenceVisualization extends XYVisualization{
020 protected ReferenceDimension xAxis, yAxis;
021 protected ValueDimension zAxis; // used as correlation
022 protected int[][] value; // value of the points
023 protected String[] info;
024 protected static int SELECT_OPTION;
025
026
027 public Dimension[] createDimension() {
028 value = null;
029 xAxis = new ReferenceDimension();
030 yAxis = new ReferenceDimension();
031 zAxis = null;
032 info = new String[3];
033
034 Dimension[] returnVal = new Dimension[2];
035 returnVal[0] = xAxis;
036 returnVal[1] = yAxis;
037
038 SELECT_OPTION = 0x0011;
039 return returnVal;
040 }
041
042 protected void updateConfiguration() {
043 canvas.setName(xAxis.getName(), yAxis.getName());
044 super.updateConfiguration();
045 }
046
047 public void preVisualize() {
048 timeMap.clear();
049 }
050
051 public ReferenceDimension getLinkableDimension(int dim) {
052 if (dim > 1)
053 return null;
054 return (ReferenceDimension)dimension[dim];
055 }
056
057 public void makeSelection() {
058 if (SELECT_OPTION == 0) {
059 Scene.showErrorMessage("Nothing will be selected, please check Selection menu.");
060 return;
061 }
062
063 if (dataSourceId != Scene.getDataSourceManager().getCurrentDataSourceId()) {
064 Scene.showErrorMessage("The active data source used currently is different from \n" +
065 "this visualization, please choose \"" +
066 Scene.getDataSourceManager().getUsedDataSourceName(dataSourceId)+"\".");
067 return;
068 }
069
070 int x1 = canvas.getStartX();
071 int x2 = canvas.getEndX();
072 int y1 = canvas.getEndY();
073 int y2 = canvas.getStartY();
074
075 if (((x1<0)&&(x2<0)) || ((x1>=xAxis.getEntityNumber()))&&(x2>=xAxis.getEntityNumber()) ||
076 ((y1<0)&&(y2<0)) || ((y1>=yAxis.getEntityNumber())&&(y2>=yAxis.getEntityNumber())))
077 return;
078
079 if (x1 < 0) {
080 x1 = 0;
081 }
082
083 if (x2 > (xAxis.getEntityNumber() - 1)) {
084 x2 = xAxis.getEntityNumber() - 1;
085 }
086
087 if (y1 < 0) {
088 y1 = 0;
089 }
090
091 if (y2 > (yAxis.getEntityNumber() - 1)) {
092 y2 = yAxis.getEntityNumber() - 1;
093 }
094
095 int[] selection = null;
096 switch (SELECT_OPTION & 0xf0f0) {
097 case 0x1000: // select occurred entities on x axis
098 ArrayList idList = new ArrayList();
099 for (int i=x1; i<=x2; i++) {
100 for (int j=y1; j<=y2; j++) {
101 if (image.getSortedColor(xAxis,yAxis,i,j) != null)
102 idList.add(new Integer(i));
103 }
104 }
105 selection = new int[idList.size()];
106 for (int i=0; i<idList.size(); i++)
107 selection[i] = ((Integer)idList.get(i)).intValue();
108 xAxis.makeSelection(subjectDefinition.getType(),selection);
109 break;
110 case 0x0010: // select all entities on x axis
111 selection = new int[x2-x1+1];
112 for (int i=x1; i<=x2; i++)
113 selection[i-x1] = i;
114 xAxis.makeSelection(subjectDefinition.getType(),selection);
115 break;
116 case 0x0000: // x axis is not seletcted
117 /*x1 = 0;
118 x2 = xAxis.getEntityNumber() - 1;
119 selection = new int[x2-x1+1];
120 for (int i=0; i<=x2; i++)
121 selection[i] = i;*/
122 break;
123 }
124
125 switch (SELECT_OPTION & 0x0f0f) {
126 case 0x0100: //select occurred entities
127 ArrayList idList = new ArrayList();
128 for (int i=x1; i<=x2; i++) {
129 for (int j=y1; j<=y2; j++) {
130 if (image.getSortedColor(xAxis,yAxis,i,j) != null)
131 idList.add(new Integer(i));
132 }
133 }
134 selection = new int[idList.size()];
135 for (int i=0; i<idList.size(); i++)
136 selection[i] = ((Integer)idList.get(i)).intValue();
137 yAxis.makeSelection(subjectDefinition.getType(),selection);
138 break;
139 case 0x0001: // select all entities
140 selection = new int[y2-y1+1];
141 for (int i=y1; i<=y2; i++)
142 selection[i-y1] = i;
143 yAxis.makeSelection(subjectDefinition.getType(),selection);
144 break;
145 case 0x0000:
146 /*y1 = 0;
147 y2 = yAxis.getEntityNumber() - 1;
148 selection = new int[y2-y1+1];
149 for (int i=0; i<=y2; i++)
150 selection[i] = i;*/
151 break;
152 }
153
154 }
155
156 /**
157 * Mouse moved.
158 *
159 * @param x position on X-axis
160 * @param y position on Y-axis
161 */
162 protected void mouseMove(int x, int y) {
163 int X = canvas.getImageX(x);
164 int Y = canvas.getImageY(y);
165
166 if ((X >= 0) && (X < xAxis.getEntityNumber()) && (Y >= 0) && (Y < yAxis.getEntityNumber())) {
167
168 if (shift_pressed && (image.getSortedColor(xAxis,yAxis,X,Y)==null))
169 Scene.setStatus(" ");
170 else {
171 if (value == null)
172 Scene.setStatus(info[0] + xAxis.getEntity(X).getName() + info[1] +
173 yAxis.getEntity(Y).getName() + info[2]);
174 else {
175 HashMap mapX = xAxis.getEntityName2IntMap();
176 HashMap mapY = yAxis.getEntityName2IntMap();
177 String xName = xAxis.getEntity(X).getName(), yName = yAxis.getEntity(Y).getName();
178 Scene.setStatus(info[0] + xName + info[1] + yName +
179 info[2] + value[((Integer)mapX.get(xName)).intValue()][((Integer)mapY.get(yName)).intValue()]);
180 }
181 }
182 } else {
183 Scene.setStatus(" ");
184 }
185 }
186
187 public void sort() {
188 try {
189 int before1 = xAxis.getEntityNumberBeforeLink();
190 int before2 = xAxis.getEntityNumberBeforeLink();
191 canvas.setName(xAxis.getName() + " (" + ((before1 == -1) ? "" : (""+before1+" / "))
192 + xAxis.getEntityNumber() +
193 ", " + xAxis.getSelectedComparatorName() + ")",
194 yAxis.getName() + " (" + ((before2 == -1) ? "" : (""+before2+" / "))
195 + yAxis.getEntityNumber() +
196 ", " + yAxis.getSelectedComparatorName() + ")");
197 canvas.setImage(image.getSortedImage(xAxis, yAxis).getImage());
198 canvas.repaint();
199 enableBrowseSourceMenu();
200 } catch (NoDataPlotException e) {
201 Scene.showErrorMessage(e.getMessage());
202 }
203 }
204
205 protected void changeOrientation() {
206 super.changeOrientation();
207 ReferenceDimension temp = xAxis;
208 xAxis = yAxis;
209 yAxis = temp;
210 String tempInfo = info[0];
211 info[0] = info[1];
212 info[1] = tempInfo;
213 sort();
214 }
215
216 public int[][] getValue() {
217 return value;
218 }
219
220 public void setValue(int[][] newValue) {
221 value = newValue;
222 }
223
224 protected String getEntityUnderMouse() {
225 return null;
226 }
227
228 public Object clone() {
229 ReferenceReferenceVisualization o = null;
230
231 o = (ReferenceReferenceVisualization)super.clone();
232 o.xAxis = (ReferenceDimension)xAxis.clone();
233 o.yAxis = (ReferenceDimension)yAxis.clone();
234 o.zAxis = (ValueDimension)zAxis.clone();
235 o.dimension[0] = o.xAxis;
236 o.dimension[1] = o.yAxis;
237 o.dimension[2] = o.zAxis;
238 o.createMenu();
239 if (value != null) {
240 o.value = new int[value.length][];
241 for (int i=0; i<value.length; i++) {
242 o.value[i] = new int[value[i].length];
243 for (int j=0; j<value[i].length; j++)
244 o.value[i][j] = value[i][j];
245 }
246 }
247 if (info != null) {
248 o.info = new String[info.length];
249 for (int i=0; i<info.length; i++)
250 o.info[i] = info[i];
251 }
252 o.panelConfiguration = o.createConfigurationPanel();
253 o.createDialog();
254 return o;
255 }
256 }